<!DOCTYPE html>
<html>
<head><#include "/base/head.html">
</head>

<script type="text/javascript">
	var userDogs = new Object();

	var step = 1;

	console.log(BaseJs.getCookie("diseaseCf"));
	BaseJs.clearCookie();
	console.log(document.cookie);
	$(function() {
		/*
		$("#userDogs input[type='radio']").click(function() {
			//var dogId = $(this).val();
			BaseJs.ajax("${contextPath}/expert/dog/getUserDogDetail", null, function(data) {
				console.log(data);

			});
		});*/
		function arrayContain(key, array) {
			for ( var i in array) {
				if (array[i] == key)
					return true;
			}
			return false;
		}

		function formToJson(form, isUnchecked) {
			var data = $(form).serializeArray();
			var params = new Array();

			for ( var i in data) {
				if (data[i].name == 'ssym')
					params.push(data[i].value);
			}

			data = new Object();

			var jsonRows = JSON.stringify(params);
			var ret = new Object();
			ret.symptomsId = params;

			var uncheckArray = new Array();
			if (isUnchecked) {
				$("input[name='ssym']").not("input:checked").each(function() {
					var key = $(this).val().toString();
					uncheckArray.push(key);

				});
			}
			var uncheckJson = JSON.stringify(uncheckArray);
			ret.uncheckList = uncheckArray;
			return ret;
		}

		function nextClick() {

			var data = formToJson("#symptomForm",true);

			BaseJs.ajax("${contextPath}/expert/getNextCheckRet", data, function(r) {

				$("#resultContent").html("");
			console.log(r.data);
				for ( var i in r.data) {
					$("#resultContent").append('&nbsp;&nbsp;你有' + (r.data[i].sumCf / 100) + '"%的可能性是' + ' <a  target="_blank" href="${contextPath}/expert/disease_show?id=' + r.data[i].id + '">' + r.data[i].name + '</a>')
				}
				$("#choicesContext").html("");
				var choseAgain = $("<input type='button' value='继续选择症状确定疾病'>");

				choseAgain.click(function() {
					BaseJs.ajax("${contextPath}/expert/choseAgain", null, function(r) {
						$("#choicesContext").html("");
						var table = $("<table>");
						var data = r.data;
						for ( var i in data) {
							table.append("<tr><td><input type='checkbox' name='ssym' value='"+data[i].id+"'></td><td>" + data[i].name + "</td></tr>");
						}
						$("#choicesContext").append(table);
						var sub = $('<input type="button" id="ssubmit" value="确定"></input>');
						$("#choicesContext").append(sub);
						sub.click(function() {
							nextClick();
						})
					});
				});
				$("#choicesContext").append(choseAgain);
			});
		}

		$("#fsubmit").click(function() {

			var data = formToJson("#symptomForm",false);

			BaseJs.ajax("${contextPath}/expert/getFirstCheckRet", data, function(r) {
				var data = r.data;
				step = 2;

				$("#choicesContext").html("");
				var table = $("<table>");
				for ( var i in data) {
					table.append("<tr><td><input type='checkbox' name='ssym' value='"+data[i].id+"'></td><td>" + data[i].name + "</td></tr>");
				}

				$("#choicesContext").append(table);
				$("#choicesContext").append('<input type="button" id="ssubmit" value="请继续选择您狗狗的病症(下一步)"></input>');

				$("#ssubmit").click(function() {
					nextClick();
				});

			});
		});

	});
</script>

<body>
	<form id="symptomForm">

		<div style="margin: 10px">
			诊断结果显示：
			<div id="resultContent"></div>
		</div>
		请选择你狗狗的症状：
		<script type="text/javascript">
			$(function() {
				$(document).on("click", ".firstSymptom", function() {
					var t = this;
					$(".firstSymptom").each(function() {

						var cSymptom = $(this).parents("tr").next().find(".secondSymptom");
						if (!$(this).is(t))
							cSymptom.parent().slideUp("slow");
					});

					var secondSymptom = $(this).parents("tr").next().find(".secondSymptom");
					console.log(secondSymptom);
					secondSymptom.parent().slideDown("slow");
				});
			});
		</script>
		<div id="choicesContext">
			<table cellpadding="7">
				<tr style="text-align: center;">
					<th>狗狗的症状名</th>
					<!-- <th>症状描述</th> -->
				</tr>
				<#list symptoms as symptom>
				<tr>
					<!-- <td><input type="checkbox" name="symptoms"></td> -->
					<td><input type="button" class="firstSymptom" value="${symptom.name}" sid="${symptom.id}" /></td>
					<td><#if symptom.description?exists> ${symptom.description} </#if></td>

				</tr>
				<tr>
					<td colspan="2">
						<div style="display: none;">
							<table class="secondSymptom">
								<#if symptom.childs?exists>
								<tr>
									<#list symptom.childs as s2>
									<td style="padding: 0 20px 0 20px"><input type="checkbox" name="ssym" value="${s2.id}" sid="${s2.id}" />${s2.name}</td> </#list>
								</tr>
								</#if>
							</table>
						</div>
					</td>
				</tr>
				</#list>
			</table>
			<input type="button" id="fsubmit" value="症状选择完毕(下一步)"></input>
		</div>

	</form>

</body>
</html>